package com.lanou.mynews.issue;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.lanou.mynews.R;
import com.lanou.mynews.news.NewContentEntity;

import java.util.List;

/**
 * Created by dllo on 16/1/25.
 */
public class IssueContentActivity extends AppCompatActivity {

    private ListView listView;
    private IssueContentAdapter adapter;
    private RequestQueue requestQueue;
    private List<IssueContentEty.DataEntity.HotListEntity> datas;
    private TextView textView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.issue_content);

        listView = (ListView) findViewById(R.id.listview);

        requestQueue = Volley.newRequestQueue(this);
        String getUrl = "http://c.m.163.com/newstopic/qa/" + getIntent().getStringExtra("b") + ".html";
        StringRequest request = new StringRequest(getUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                if (response != null) {
                    Gson gson = new Gson();
                    IssueContentEty issueContentEty = gson.fromJson(response,
                            IssueContentEty.class);
                    if (issueContentEty != null) {
                        datas = issueContentEty.getData().getHotList();

                        //绑定适配器
                        adapter = new IssueContentAdapter(IssueContentActivity.this,datas);
                        listView.setAdapter(adapter);

                    }
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        requestQueue.add(request);


    }
}
